liwe.form5.templates = {
	'form-start' : '<form id="%(_id)s" name="%(name)s" class="%(class)s" role="form" onsubmit="return liwe.form5.on_event( \'submit\', event,this)" onreset="return liwe.form5.on_event( \'reset\', event,this)">',
	'form-end' : '</form>',
	'label' : '<div class="form-group" id="fg-%(_id)s"><label for="%(_id)s" class="control-label">%(label)s</label>',
	'input' : '<input id="%(_id)s" class="form-control" %(_attrs)s value="%(_value)s"/></div>',
	'submit' : '<input class="btn btn-success" id="%(_id)s" %(_attrs)s value="%(_value)s"/>',
	'reset' : '<input class="btn btn-warning" id="%(_id)s" %(_attrs)s value="%(_value)s"/>',
	'mandatory' : '<span id="%(_id)s-mandatory" class="mandatory"></span>',
	'mandatory-clear' : 'O',
	'mandatory-err' : 'X',
	'mandatory-ok' : 'V',
	'validation' : '<span id="%(_id)s-validation" class="validation"></span>',
	'validation-clear' : '1',
	'validation-err' : '2',
	'validation-ok' : '3',
	'nl' : '', // <br />',
	'filter' : 'return liwe.form5._evt_keypress(\'%(_form_name)s\',\'%(_id)s\',event)',
	'group-start' : '<fieldset>',
	'group-label' : '<legend>%(label)s</legend>',
	'group-end'   : '</fieldset>',

/* PLUGINS */
	'textarea' : '<textarea id="%(_id)s" class="form-control" %(_attrs)s />%(_value)s</textarea>',
	'select' : '<select class="form-contol" id="%(_id)s" %(_attrs)s">'	
};

liwe.form5.__set_mandatory = function ( item, templ_name )
{
	var res = "";

	switch ( templ_name )
	{
		case "err":
			res = "has-error";
			break;
		case "ok":
			res = "has-success";
			break;
	};

	$( "fg-" + item [ '_id' ] ).className = "form-group " + res;
};

liwe.form5.set_mandatory  = liwe.form5.__set_mandatory;
liwe.form5.set_validation = liwe.form5.__set_mandatory;

// {{{ checkbox ( frm, type, name, attrs ) - Form checkboxes


liwe.form5.templates [ 'checkbox' ] = '<div class="checkbox" id="fg-%(_id)s"><label><input id="%(_id)s" %(_attrs)s value="%(_value)s"/> %(label)s</label></div>';

liwe.form5.plugin_add ( 'checkbox', function ( frm, type, name, attrs )
{
	attrs [ 'get_value' ] = function ()
	{
		var item = $( attrs [ '_id' ] );
		if ( ! item || ! item.checked ) return null;
		return item.value;
	};

	attrs [ 'template' ] = 'checkbox';

	attrs [ 'render' ] = function ( form, item )
	{
		var res = String.formatDict ( form.templates [ attrs [ 'template' ] ], attrs );
		return { item: res, label: '' };
	};
} );
// }}}
